#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#define High 18
#define Width 30

int main(){
	int pos_x = Width / 2;   //飞机位置
	int pos_y = High / 2;
	int bullet_x = -1, bullet_y = -1;    //子弹位置
	int bazi_x = Width / 2,bazi_y = 1; //靶子
	char c;
	int score = 0;
	int i, j;
	while(1){
		system("cls");
		for (i = 1; i <= High; i ++){
			for (j = 1; j <= Width; j ++){
				if (i == pos_y && j == pos_x){                                //打印飞机
					printf ("*");
				}
				else if (i == pos_y && j == pos_x+1){
					printf ("*");
				}
			    else if (i == pos_y && j == pos_x-1){
					printf ("*");
				}
				else if (i == pos_y-1 && j == pos_x){
					printf ("*");
				}
				else if (i == pos_y-2 && j == pos_x){
					printf ("*");
				}
				else if (i == pos_y-3 && j == pos_x){
					printf ("*");
				}
				else if (i == pos_y-2 && j == pos_x-1){
					printf ("*");
				}
				else if (i == pos_y-2 && j == pos_x+1){
					printf ("*");
				}
			    else if (i == pos_y-2 && j == pos_x-2){
					printf ("*");
				}
				else if (i == pos_y-2 && j == pos_x+2){
					printf ("*");
				}
				else if (i == High){
					printf ("_");
				}
				else if (j == Width){
					printf ("|");
				}
			    else if (i == bullet_y && j == bullet_x){
					printf ("|");
				}
		        else if (i <= bazi_y && j == bazi_x){
					printf ("$");
				}
				else
					printf (" ");
				
			}
			printf("\n");
			
		}
		printf ("分数：%d", score);
		if(kbhit()){  // 判断是否有输入
			c = getch();
			if (c == 'w')
				pos_y--;
			else if (c == 's')
				pos_y++;
			else if (c == 'a')
				pos_x--;
			else if (c == 'd')
				pos_x++;
			else if (c == ' '){
				bullet_x = pos_x;
				bullet_y = pos_y - 4;
			}
		}
		if (bullet_x == bazi_x && bullet_y == bazi_y){
			bazi_x = rand() % Width;
			bazi_y = 1;
			score++;
		}




		bullet_y--;

		
	}
	
	
	
	
	return 0;
}